/*
 * =====================================================================================
 *
 *       Filename:  poll.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  08/14/2012 11:08:59 AM
 *       Revision:  none
 *       Compiler:  gcc/g++
 *
 *         Author:  wangtengchao , wangtengchao AT gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef POLL_H
#define POLL_H
#include "demultiplexer.h"
#include <poll.h>
#include <vector>
namespace inm
{
    namespace net
    {
        class Dispatcher;
        typedef std::vector<struct pollfd> PollEventVector;
        //can accept 9 clinets because index 0 is for listerner
        const static int InitialMaxFd = 10;
        const static int DefaultMaxFd = 1024;

        class Poll : public Demultiplexer
        {
        public:
            Poll();
            ~Poll();
            void registerEvent(int fd,const short& et);
            void updateEvent(int fd,const short& et);
            void removeEvent(int fd,const short& et);
            void handleEvents(int timeout);
        private:
            PollEventVector vPollfd_;
            int lowestFreeFdIndex_;
            int maxUsedFdIndex_;
            //can be set by getenv .now is not used and the largest files fd is 1024
            int systemMaxFd;
        };

    }
};


#endif
